﻿#region Copyright(C) 2018 FI Ltd. All rights reserved.
// ==================================================================================================
// Copyright(C) 2018 FI Ltd. All rights reserved.
//
// SYSTEM NAME	    : FI.Net Application Framework
// COMPONENT ID	    : FI.Core
// COMPONENT DESC   : FI.Net Core Foundation
//
// CREATED DATE/BY  : 18 Aug 2018 / Tian Mi
//
// REVISION HISTORY :	
// DATE/BY			SR#/CS/PM#/OTHERS		DESCRIPTION OF CHANGE
// ==================================================================================================
#endregion

namespace FI.Core.Caching
{
    /// <summary>
    /// This interface defines the basic functionalities of a cache store.
    /// </summary>
    public interface ICacheStore
    {
        /// <summary>
        /// Gets a value indicating whether this <see cref="ICacheStore"/> is enabled.
        /// </summary>
        /// <value>
        ///   <c>true</c> if enabled; otherwise, <c>false</c>.
        /// </value>
        bool Enabled { get; }

        /// <summary>
        /// Adds the specified value into cache.
        /// </summary>
        /// <param name="key">The key of the cache item to be added.</param>
        /// <param name="value">The value of the cache item to be added.</param>
        void Add(string key, object value);

        /// <summary>
        /// Adds or replaces an object in the cache.
        /// </summary>
        /// <param name="key">The unique value that is used to identify the object in the cache.</param>
        /// <param name="value">The object to add or replace.</param>
        void Put(string key, object value);

        /// <summary>
        /// Remove specified cahce item.
        /// </summary>
        /// <param name="key">The key of cache item to be deleted.</param>
        void Remove(string key);

        /// <summary>
        /// Tries the get value of the cache item based on the given key.
        /// </summary>
        /// <param name="key">The key of the cache item.</param>
        /// <param name="value">The value of the cache item.</param>
        /// <returns>A <see cref="bool"/> value indicating whether to get the value from cache store.</returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1007:UseGenericsWhereAppropriate")]
        bool TryGetData(string key, out object value);

        /// <summary>
        /// Tries the get value of the cache item based on the given key.
        /// </summary>
        /// <typeparam name="T">The type of the cache item's value.</typeparam>
        /// <param name="key">The key of the cache item.</param>
        /// <param name="value">The value of the cache item.</param>
        /// <returns>
        /// A <see cref="bool" /> value indicating whether to get the value from cache store.
        /// </returns>
        bool TryGetData<T>(string key, out T value);

        /// <summary>
        /// Remove all cache items added by the cache store itself.
        /// </summary>
        void Clear();
    }
}